//
//  Message_DetaileVc_Complain.swift
//  Pods
//
//  Created by eme on 2017/4/11.
//
//
/*
 owner:gyh
 update:2017年01月19日14:08:08
 info: 消息详情(投诉消息)
 */
import UIKit
import UtilCore
import RickonCore

class Message_DetaileVc_Complain: Base_Vc {
    
    /****************************Storyboard UI设置区域****************************/
    
    @IBOutlet weak var Custom_TableView: UITableView!                   //表
    
    /*----------------------------   自定义属性区域    ----------------------------*/
    var requestID:String?
    var GetMessageDetaile:GetMessageDetaileVm?
    var detaileModel:ComplaintsDetaileModel?{
        didSet{
            self.Custom_TableView.reloadData()
        }
    }
    
    /****************************Storyboard 绑定方法区域****************************/
    
    
    
    /**************************** 以下是方法区域 ****************************/
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = false
        self.GetMessageDetaile?.get_complainid.onNext(self.requestID ?? "")
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    /**
     界面基础设置
     */
    override func setupUI() {
        /**
         *  自定义 导航栏左侧 返回按钮
         */
        self.customLeftBarButtonItem()
        self.setUpTableView()
    }
    func setUpTableView(){
        
        self.Custom_TableView.showsVerticalScrollIndicator = false
        Custom_TableView.delegate = self
        Custom_TableView.dataSource = self
        Custom_TableView.rowHeight = UITableViewAutomaticDimension
        Custom_TableView.estimatedRowHeight = 200
    }
    /**
     绑定到viewmodel 设置
     */
    override func bindToViewModel(){
        
        self.GetMessageDetaile = GetMessageDetaileVm()
        
        self.GetMessageDetaile?.result.subscribe(onNext:{ result in
            
            self.detaileModel = result
            
            }).addDisposableTo(disposeBag)
        
        self.GetMessageDetaile?.loading.bindTo(self.view.rx_loading).addDisposableTo(disposeBag)
        
        self.GetMessageDetaile?.error.bindTo(self.view.rx_error).addDisposableTo(disposeBag)
    }
}
extension Message_DetaileVc_Complain:UITableViewDelegate,UITableViewDataSource{
    func numberOfSections(in tableView: UITableView) -> Int {
        if let _ = detaileModel{
            return 4
        }else{
            return 0
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch section {
        case 0:
            return 1
        case 1:
            return 1
        case 2:
            return 1
        case 3:
            return 2
        default:
            return 0
        }
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headercell = tableView.dequeueReusableCell(withIdentifier: "header") as! Complaints_Header_TableViewCell
        switch section {
        case 3:
            return headercell
        default:
            return nil
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        switch section {
        case 3:
            return 44
        case 0:
            return 0.1
        default:
            return 0.1
        }
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let typeCell = tableView.dequeueReusableCell(withIdentifier: "type") as!  Complaints_Type_TableViewCell
        let progressCell = tableView.dequeueReusableCell(withIdentifier: "progress") as! Complaints_Progress_TableViewCell
        if indexPath.row == 0{
            progressCell.Black_Ball.backgroundColor = UIColor.black
            progressCell.top_Line.isHidden = true
            progressCell.bottom_Line.isHidden = false
        }else{
            progressCell.Black_Ball.backgroundColor = UIColor(hex: "999999")
            progressCell.bottom_Line.isHidden = true
            progressCell.top_Line.isHidden = false
        }
        //---------此处的提示在配置文件中
        progressCell.type_Label.text = ["投诉已处理",UtilCore.alertmsg[100054009]!.msgtitle][indexPath.row]
        progressCell.Message_Label.text = ["\(UtilCore.alertmsg[100054010]!.msgtitle)，处理问题：\(detaileModel!.reply)",UtilCore.alertmsg[100054011]!.msgtitle][indexPath.row]
        //---------此处提示在配置文件中
        progressCell.time_Label.text = [self.detaileModel?.replydate,self.detaileModel?.complaindate][indexPath.row]
        let messageCell = tableView.dequeueReusableCell(withIdentifier: "message") as! Complaints_Message_TableViewCell
        messageCell.item = self.detaileModel
        let goodCell = tableView.dequeueReusableCell(withIdentifier: "goods") as! Complaints_Goods_TableViewCell
        goodCell.item = self.detaileModel?.detail
        

        switch indexPath.section {
        case 0:
            guard #available(iOS 9.0, *) else {
                typeCell.setNeedsUpdateConstraints()
                typeCell.updateConstraintsIfNeeded()
                return typeCell
            }
            return typeCell
        case 1:
            guard #available(iOS 9.0, *) else {
                goodCell.setNeedsUpdateConstraints()
                goodCell.updateConstraintsIfNeeded()
                return goodCell
            }
            return goodCell
        case 2:
            guard #available(iOS 9.0, *) else {
                messageCell.setNeedsUpdateConstraints()
                messageCell.updateConstraintsIfNeeded()
                return messageCell
            }
            return messageCell
        default:
            guard #available(iOS 9.0, *) else {
                progressCell.setNeedsUpdateConstraints()
                progressCell.updateConstraintsIfNeeded()
                return progressCell
            }
            return progressCell
        }
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 5
    }
}
